const { pool, add, edit } = require('./baseModel.js')

exports.add = async (fields) => {
    return await add('comment_info', fields)
}

exports.delete = async (id) => {
    return edit('comment_info', { isDel: 1 }, { id })
}

exports.findByFid = async (fid, pageIndex) => {
    let result = await pool.query('select m.*,u.nickName,u.user_photo,f.food_name from comment_info as m left join user_info as u on m.uid=u.id left join food_info as f on m.fid=f.id where m.isDel=0 and fid=? order by id desc limit ?,10', [fid, (pageIndex - 1) * 10])
    return result[0]
}

exports.findAll = async (fid) => {
    let result = await pool.query('select count(*) as total from comment_info where fid=? and isDel=0', [fid])
    return result[0]
}
